package com.xinqi.modules.prepare.paper.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareExamPaperData;
import com.xinqi.modules.prepare.paper.domain.PrepareExamPaperEntity;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperCreateDTO;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperRandomDTO;
import com.xinqi.modules.prepare.paper.dto.req.PrepareExamPaperUpdateDTO;
import com.xinqi.modules.prepare.paper.dto.rsp.PrepareExamPaperResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区测评卷转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareExamPaperConvert {
    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareExamPaperEntity create(PrepareExamPaperCreateDTO s);

    public abstract PrepareExamPaperCreateDTO create(PrepareExamPaperData data);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareExamPaperEntity update(PrepareExamPaperUpdateDTO s, @MappingTarget PrepareExamPaperEntity t);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getQuestionContent()))")
    public abstract PrepareExamPaperEntity update(PrepareExamPaperUpdateDTO s);

    @Mapping(target = "questionContent", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getQuestionContent(), com.xinqi.common.base.dto.QuestionBaseDTO.class))")
    public abstract PrepareExamPaperResultDTO convert(PrepareExamPaperEntity s);

    public abstract PrepareExamPaperData convert(PrepareExamPaperResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareExamPaperEntity copy(PrepareExamPaperEntity sources, @MappingTarget PrepareExamPaperEntity prepareExamPaperEntity);

    public abstract PrepareExamPaperCreateDTO convert(PrepareExamPaperRandomDTO dto);
}
